import * as React from "react";
import { AsyncStorage, Dimensions, StatusBar } from "react-native";
import { Toast } from "@ant-design/react-native";
import axios from "axios";

//获取手机宽高
const w = Dimensions.get("window").width;
const h = Dimensions.get("window").height;
//获取状态栏高度
const Bar = StatusBar.currentHeight;
//接口菜谱数量，后期可修改
const number=56390;
//请求地址
const QQurl='https://way.jd.com/jisuapi/';
//密钥后期可更换
const urlkey='bec2e7149cdb9025223c746836950d67';




//axios请求封装
function QQ(url,data,type){
  //显示loading加载框
  const key = Toast.loading('加载中...', 0, () => {});
  return new Promise((resolve, reject) => {
    if (type=='post'){
      axios.post(QQurl,data).then(res=>{
        resolve(res.data);
        Toast.remove(key);
      }).catch(err =>{
        reject(err.data)
        Toast.remove(key);
      })
    }else {
      //请求数据都得写成地址
      axios.get(QQurl+url+urlkey,data).then(res=>{
        resolve(res.data)
        Toast.remove(key)
      }).catch(err =>{
        reject(err.data)
        Toast.remove(key)
      })
    }
  })
}


module.exports = {
  w,
  h,
  Bar,
  QQ,
  number
};
